import com.sun.scenario.effect.impl.sw.java.JSWBlend_SRC_OUTPeer;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.resps.Tuple;

import java.time.format.SignStyle;
import java.util.List;

public class test {

    public static void main(String[] args) {
        test jt = new test();
        jt.testhash();
    }

    public void testjedis(){
        Jedis jedis = new Jedis("localhost",6379);
        jedis.set("name","zhangsan");
        System.out.println(jedis.get("name"));
        jedis.close();
    }
    public void testhash(){
        Jedis jedis = new Jedis("localhost",6379);
        jedis.hset("myhash","name","zhangsan");
        jedis.hset("myhash","age","18");
        jedis.hset("myhash","height","1.68");
        System.out.println(jedis.hgetAll("myhash"));
        for(String  s : jedis.hkeys("myhash")){
            System.out.println(s+jedis.hget("myhash",s));
        }
        jedis.close();
    }

    public void testlist(){
        Jedis jedis = new Jedis("localhost",6379);
        jedis.lpush("list","a","b","c");
        jedis.rpush("list","d","e","f");

        List<String> list=jedis.lrange("list",0,-1);
        for (String s : list) {
            System.out.println(s);
        }
        jedis.close();
    }

    public void testset(){
        Jedis jedis = new Jedis("localhost",6379);
        jedis.sadd("list","a","b","c");
        jedis.sadd("list","d","e","f");
        for (String s : jedis.smembers("list")) {
            System.out.println(s);
        }
        boolean flag=jedis.sismember("list","d");
        System.out.println(flag);
    }

    public void testzset(){
        Jedis jedis = new Jedis("localhost",6379);
        jedis.zadd("gameranking",100,"player1");
        jedis.zadd("gameranking",200,"player2");
        jedis.zadd("gameranking",300,"player3");

        List<String> rank=jedis.zrevrangeByScore("gameranking",500,0);
        for (String s : rank) {
            System.out.println(s);
        }

        List<Tuple> tuples=jedis.zrevrangeWithScores("gameranking",0,1);
        for (Tuple tuple : tuples) {
            System.out.println(tuple.getElement()+" "+tuple.getScore());
        }
    }
}
